chore: allow running and linting docs notebooks#493
Conversation
📝 WalkthroughWalkthroughAdds bootstrap reminders, docs helper targets, a Python snippet linter with tests, and a Fern notebook runner with tests and usage docs. ChangesDocumentation tooling
Sequence Diagram(s)sequenceDiagram
participant Makefile
participant Lint as lint_python_snippets.py
participant Ast as ast.parse
participant Ty as ty
Makefile->>Lint: uv run --frozen python docs/_scripts/lint_python_snippets.py DOCS_PATH
Lint->>Ast: parse fenced python snippets
Lint->>Ty: uv run --frozen ty check
Ty-->>Lint: diagnostics
Lint-->>Makefile: exit code
sequenceDiagram
participant Makefile
participant Runner as run_notebooks.py
participant Notebook as NotebookSelection
participant Executor as nmp.testing.notebooks.execute_notebook
Makefile->>Runner: uv run --frozen python docs/fern/scripts/run_notebooks.py $(ARGS) $(DOCS_PATH)
Runner->>Runner: select_notebooks(paths)
Runner->>Notebook: resolve notebook/source pairs
Runner->>Executor: execute selected notebook
Executor-->>Runner: result
Runner-->>Makefile: exit code
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/_scripts/lint_python_snippets.py`:
- Around line 260-263: The temp file naming in PreparedTypeCheckFile creation is
vulnerable to collisions because the sanitized doc_path-based name in the
temp_path construction can overlap for different documents, and prefix-based
matching can misroute diagnostics when temp paths share prefixes. Update the
path generation and lookup logic around PreparedTypeCheckFile, temp_path, and
the diagnostic mapping code in the affected snippet to use a collision-proof
unique identifier per document and exact temp_path equality when resolving
diagnostics, so each source document maps to only its own temporary file and
line mapping.
In `@docs/AGENTS.md`:
- Around line 15-16: The Makefile examples in the docs use the wrong variable
name, so update the documented invocations for docs-check-python-snippets and
docs-run-notebook to use DOCS_PATH instead of DOC_PATH. Keep the wording aligned
with the actual Makefile contract and ensure the examples match the target names
so users can copy them without hitting the empty-variable guard.
In `@docs/fern/scripts/README.md`:
- Around line 84-86: The README examples for make docs-run-notebook use the
wrong variable name, so the commands won’t pick up the notebook path. Update
both example invocations in README to use DOCS_PATH, matching the
docs-run-notebook target and the variable referenced by Makefile; use the
docs-run-notebook command examples as the anchor for the fix.
In `@docs/fern/scripts/run_notebooks.py`:
- Around line 247-250: The MDX preprocessing in run_notebooks() happens before
the per-notebook failure handling, so a materialize_mdx_as_markdown() error can
stop the whole batch. Move the .mdx conversion inside the existing try block for
each notebook selection so include expansion or file I/O failures are caught,
the notebook is marked failed, and processing continues for the remaining items.
Use the existing run_notebooks flow and the selection.path / run_path handling
to keep the logic localized.
- Around line 33-36: Both notebook URL regexes are too strict because they only
allow a single path segment after blob/, so branch refs with slashes do not
match. Update COLAB_NOTEBOOK_RE and FERN_NOTEBOOK_RE in run_notebooks.py to
accept multi-segment refs before the docs/... notebook path, while still
capturing the notebook path in the existing named path group. Keep the rest of
the matching behavior unchanged so notebook links from .mdx pages continue to
resolve.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 00a5b4ad-15c8-4326-902a-b5046d93d3e0
📒 Files selected for processing (7)
Makefiledocs/AGENTS.mddocs/_scripts/lint_python_snippets.pydocs/_scripts/test_lint_python_snippets.pydocs/fern/scripts/README.mddocs/fern/scripts/run_notebooks.pydocs/fern/scripts/test_run_notebooks.py
|
tylersbray
left a comment
There was a problem hiding this comment.
Approving but do the code rabbit stuff please.
benmccown
left a comment
There was a problem hiding this comment.
LGTM, my only suggestion from chatting with claude is that we consider adding *.tmp.md to .gitignore in case a SIGKILL interrupts while files are presently copied, to avoid accidentally committing them. Not a big deal though, pretty unlikely and I'd hope humans would catch it.
Signed-off-by: Matt Kornfield <mkornfield@nvidia.com>
Signed-off-by: Matt Kornfield <mkornfield@nvidia.com>
Signed-off-by: Matt Kornfield <mkornfield@nvidia.com>
276228b to
d61e5b4
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/_scripts/lint_python_snippets.py`:
- Around line 355-359: The failure handling in lint_python_snippets.py currently
only surfaces non-zero ty/uv exits when unmatched_lines exists, so silent
failures can be missed. Update the result path around the completed.returncode
check to treat any non-zero exit as a failure even when results is empty, using
the existing completed, results, unmatched_lines, and snippets_by_path flow. If
there are no collected messages, return a shared failure message or equivalent
non-empty output for all affected paths so ty/uv errors cannot pass silently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 2ff08f86-79c3-4816-88b1-989850432cd2
📒 Files selected for processing (11)
.claude/commands/docs-lint.md.claude/commands/docs-test.mdMakefiledocs/.gitignoredocs/AGENTS.mddocs/_scripts/lint_python_snippets.pydocs/_scripts/test_lint_python_snippets.pydocs/fern/scripts/README.mddocs/fern/scripts/run_notebooks.pydocs/fern/scripts/test_run_notebooks.pypytest.ini
✅ Files skipped from review due to trivial changes (6)
- docs/.gitignore
- pytest.ini
- docs/AGENTS.md
- docs/fern/scripts/README.md
- .claude/commands/docs-test.md
- .claude/commands/docs-lint.md
🚧 Files skipped from review as they are similar to previous changes (2)
- Makefile
- docs/fern/scripts/run_notebooks.py
* chore: allow running and linting docs notebooks Signed-off-by: Matt Kornfield <mkornfield@nvidia.com> * chore: address CR Signed-off-by: Matt Kornfield <mkornfield@nvidia.com> * chore: more CR address Signed-off-by: Matt Kornfield <mkornfield@nvidia.com> --------- Signed-off-by: Matt Kornfield <mkornfield@nvidia.com>
Summary by CodeRabbit
make docs-check-python-snippetsto syntax- and optionally type-check Python fenced-code snippets in Markdown/MDX.make docs-run-notebookto execute Fern documentation notebooks with marker-based selection.*.tmp.mdfiles.